package com.zmht.beike.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.zmht.beike.core.BaseAction;
import com.zmht.beike.po.StudentTwo;
import com.zmht.beike.po.TLanguage;
import com.zmht.beike.util.TimeUtil;
import com.zmht.beike.web.form.LanguageForm;

public class LanguageAction extends BaseAction {
	public ActionForward getLanguage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String studentId = request.getParameter("studentId");
		TLanguage language = null;
		if("edit".equals(request.getSession().getAttribute("action"))){
			language = this.getLanguageBiz().findByStudentId(studentId);
		}
		
		request.setAttribute("language", language);
		request.setAttribute("studentId", studentId);
		return new ActionForward("/jsp/pingce/ceping_language.jsp");
	}
	public ActionForward updateLanguage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String studentId = request.getParameter("studentId");
		LanguageForm frm = (LanguageForm)form;
		TLanguage language = new TLanguage();
		BeanUtils.copyProperties(language, frm);
		language.setCtime(TimeUtil.getYMDTime());

		if(new Integer(0).equals(language.getId()))
			this.getLanguageBiz().saveLanguage(language);
		else
			this.getLanguageBiz().updateLanguage(language);
		
		
		StudentTwo student = (StudentTwo)this.getStudentBiz().getStudentDAO().findById(StudentTwo.class, new Integer(studentId));
		student.setSumLanguage(language.getScore());
		this.getStudentBiz().getStudentDAO().updateObj(student);
		request.setAttribute("studentId", studentId);
		return new ActionForward("/beike/language.do?method=getLanguage&studentId="+studentId);
	}
}
